package threadDemo;

public class Demo7 {

    public static void main(String[] args) throws InterruptedException {
        Object lock1 = new Object();
        Object lock2 = new Object();
        Thread t1 = new Thread(() -> {
            synchronized (lock1) {
                System.out.println("t1拿到醋了！！！");
                synchronized (lock2) {
                    System.out.println("t1拿到酱了！！！");
                }
            }
        });
        Thread t2 = new Thread(() -> {
            synchronized (lock2) {
                System.out.println("t2拿到酱了！！！");
                synchronized (lock1) {
                    System.out.println("t2拿到醋了！！！");
                }
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println("main 线程结束！！！");
    }
}
